﻿using System;
using System.Text;

namespace dotHTML {
    /// <summary>
    /// Represents plain text inside an HTML document, without any surrounding
    /// tags.
    /// </summary>
    [Serializable]
    public class TextNode : Element {
        private string _text;

        /// <summary>
        /// Constructs a new blank TextNode.
        /// </summary>
        public TextNode() : this(null) { }

        /// <summary>
        /// Constructs a new TextNode with the specified text.
        /// </summary>
        /// <param name="text">The text to insert into this TextNode.</param>
        public TextNode(string text) {
            _text = text;
        }

        /// <summary>
        /// Gets or sets the text associated with this TextNode.
        /// </summary>
        public string Text {
            get { return _text; }
            set { _text = value; }
        }

        /// <summary>
        /// Unused - has no effect.
        /// </summary>
        /// <remarks>This method is overridden to make sure that no attributes
        /// are written out when a TextNode is written.</remarks>
        /// <param name="sb"></param>
        protected override void WriteLocalAttributes(StringBuilder sb) { }

        /// <summary>
        /// Returns the text associated with this TextNode.
        /// </summary>
        /// <returns>The text associated with this TextNode.</returns>
        public override string ToString() {
            return _text;
        }
    }
}
